package com.ymatou.iapi.productprice.service;

import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;

public class GetNextActivityPriceByProdIdsCall extends YmatouAutoTestCall {

	private static String opurl = "api/Price/GetNextActivityPriceByProdIds";

	public GetNextActivityPriceByProdIdsCall() {
		super(EnvSetup.getSystemUrl("productprice"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	
	public JSONObject callAndGetReturnData(int buyerId, boolean isTradeIsolation,Map<String, Integer> ProductActivityListMap) {

		try {
			JSONArray catalogArray = new JSONArray();
			ProductActivityListMap.forEach((x, y) -> {
				JSONObject tmp = new JSONObject();

				try {
					tmp.put("ProductId", x);
					tmp.put("ProductInActivityId", y);
				} catch (JSONException e) {
					e.printStackTrace();
				}
				catalogArray.put(tmp);
			});

			JSONObject requestBean = this.getJsonBean(null);
			requestBean.put("ProductActivityList", catalogArray);
			JsonBeanHelper.updateJsonBean(requestBean, MapUtil.hashMap("BuyerId", buyerId,"IsTradeIsolation",isTradeIsolation));

			return callAndGetReturnData(requestBean);

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return null;

	}

	public static void main(String[] args) {
		new GetNextActivityPriceByProdIdsCall().callAndGetReturnData(3383,false,MapUtil.hashMap("6d78eaa5-9e4d-4808-affd-ca24d3cd2caa",289910));
	}

}
